package org.dromara.admin.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 租金账单类型: RENT(租金账单), PLEDGE(押金账单), REFUND(退款账单), COMPENSATION(赔付账单), OVERDUE_RETURN(逾期回款账单)
 * 垫资账单类型: ADVANCE(垫资账单), REFUND(退款账单)
 */
@Getter
@AllArgsConstructor
public enum BillType {

    ADVANCE("ADVANCE", "垫资账单"),
    /**
     * 租金账单类型
     */
    RENT("RENT", "租金账单"),
    PLEDGE("PLEDGE", "押金账单"),
    REFUND("REFUND", "退款账单"),
    COMPENSATION("COMPENSATION", "赔付账单"),
    OVERDUE_RETURN("OVERDUE_RETURN", "逾期回款账单"),

    /**
     * 账单付款类型
     */
    PAYMENT("PAYMENT", "支付");


    /**
     * 存库用的值
     */
    private final String code;

    /**
     * 前端展示用
     */
    private final String info;

    /**
     * 根据 code 获取枚举
     */
    public static BillType getByCode(String code) {
        for (BillType type : values()) {
            if (type.getCode().equalsIgnoreCase(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("无效的类型代码: " + code);
    }

    /**
     * 根据 info 获取枚举
     */
    public static BillType getByInfo(String info) {
        for (BillType type : values()) {
            if (type.getInfo().equals(info)) {
                return type;
            }
        }
        throw new IllegalArgumentException("无效的类型: " + info);
    }
}
